<template>

  <div>
    <slotname>
      <div slot="pr" class="prbox" >
        <img src="../../assets/img/dl.webp" width="100%" height="100%">
      </div>
      <div slot="main" class="mainbox">
        <el-form  status-icon :rules="rules" :model="ruleForm" ref="ruleForm" label-width="100px" class="demo-ruleForm"
          action="http://localhost:8081/json/SpringMVC_18001010209/loginuser.do" method="post" onsubmit="togo">
          <el-form-item>
            <h1>欢迎登录</h1>
          </el-form-item>
          <el-form-item label="账号" prop="uname">
            <el-input v-model="ruleForm.uname" name="uname" ></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="upassword">
            <el-input type="password" name="upassword" v-model="ruleForm.upassword" autocomplete="off"></el-input>
          </el-form-item>
          <span style="color:red">{{mag}}</span>
          <el-form-item>
            <el-button @click="login()">登录</el-button><br>
            <span>没有账号？前往<router-link to="/zhuce">注册</router-link></span>
          </el-form-item>
            
        </el-form>
      </div>
    </slotname>
  </div>
</template>

<script>
  import slotname from "./slot"
  export default {
    name: '',
    data() {
      return {
        ruleForm: {
       uname:"",
       upassword:""},
       mag:"",
       user:{},
        rules: {
          uname: [
            { required: true, message: '请输入用户名', trigger: 'blur' },
            { min: 3, message: '长度最小 3 个字符', trigger: 'blur' },
            { pattern:/^[a-zA-Z][a-zA-Z0-9]*$/, message:'请以字母开头' , trigger: 'blur' }
          ],
          upassword: [
            { required: true, message: '请输入密码', trigger: 'blur' },
          ]
        }
      
      }
    },
    methods: {
    login(){
      this.$axios.post('/loginuser.do?uname='+this.ruleForm.uname+'&upassword='+this.ruleForm.upassword).then(
        response=>{
          this.user=response.data;
          if(this.user!=""){
              window.localStorage.setItem('uid',this.user.uid)
              window.localStorage.setItem('utype',this.user.utype)
              this.$router.push({
                  path:"/",
              })
          }else{
            this.mag="用户名或密码错误"
          }
        }
      )
    }


    
      
    },
    components: {
      slotname
    },
  }
</script>

<style>
  .prbox img {
    width: 100%;
    height: 800px;
  border-radius: 25px;
  }

  .mainbox {
    margin: 200px auto;
    width: 300px;
  }
</style>